<template>
	<view class="center">
		<view class="logo" @click="goLogin" :hover-class="!login ? 'logo-hover' : ''">
			<image class="logo-img" :src="login ? avatarUrl : avatarUrl"></image>
			<view class="logo-title">
				<text class="uer-name">Hi，{{ login ? uerInfo.UserName : '您未登录' }}  <text v-if="login">角色 </text>：{{  login ? uerInfo.RoleName:'' }}</text>
				<text class="go-login navigat-arrow" v-if="!login">&#xe65e;</text>
			</view>
		</view>

		<view class="center-list" v-if="login">
			<view class="center-list-item" @click="addCar()">
				<text class="list-icon">&#xe61a;</text>
				<text class="list-text">添加笔记</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="uni-list"  v-if="login">
			<view class="uni-list-cell uni-list-cell-pd">
				<view class="uni-list-cell-db">隐藏信息</view>
				<switch @change="openHide" :checked="hideinfo" />
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item  border-bottom" v-if="login" @click="myCar()">
				<text class="list-icon">&#xe603;</text>
				<text class="list-text">我发布的</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item border-bottom" v-if="login"   @tap="showModal" data-target="DialogModal1">
				<text class="list-icon">&#xe603;</text>
				<text class="list-text">留言建议</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item border-bottom"  @tap="more">
				<text class="list-icon">&#xe603;</text>
				<text class="list-text">关于我们</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item" v-if="login" @click="logout()">
				<text class="list-icon">&#xe609;</text>
				<text class="list-text">退出登录</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		
		<view class="cu-modal" :class="modalName=='DialogModal1'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">留言建议</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<view class="cu-form-group margin-top">
						<textarea   v-model="msg" placeholder="建议内容"></textarea>						
					</view>					
					<view class="cu-form-group margin-top">
						<view class="title">联系号码：</view>
						<input placeholder="手机或微信" v-model="phone" name="input"></input>
					</view>	
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-green text-green" @tap="hideModal">取消</button>
						<button class="cu-btn bg-green margin-left" @tap="submsg">确定</button>
		
					</view>
				</view>
			</view>
		</view>
		
	
		
	</view>
</template>

<script>
  import service from '../../service.js';
  var _self;
export default {
	data() {
		return {
			uerInfo: service.getUsers(),
			login: false,
			avatarUrl: '/static/logo.png',
			msg:'',
			phone:'',
			modalName:'',
			hideinfo:service.showHide ,
		}
	},
	 onLoad() {
		 _self=this;
		 console.log("显示"+service.showHide);
	  if(service.getUsers()!=null &&service.getUsers()!=''  ){
		  this.login=true;
		  console.log("f本地"); 
	  }
      },
	methods: {

		goLogin() {
			if (!this.login) {
				uni.navigateTo({
					url: '/pages/login/login'
				});
			}
		},
		 addCar(){
				 uni.navigateTo({
					      url: '../recordbook/addbook',
					  });
				 },
		logout(){
			uni.showModal({
				title: '退出',
				content: '确定退出吗？',
				cancelText: '取消',
				confirmText: '确定',
				success: res => {
					if (res.confirm) {
							_self.login=false;
							service.addUser('');
					}
				}
			})
				uni.showToast({
						title:"退出成功"
						})
				}
		,openHide(){
			if(service.showHide){
				service.showHide=false;
				_self.hideinfo=false;
			}
			else{
				service.showHide=true;
				_self.hideinfo=true;
			}
			console.log(service.showHide);
			 
		}
		,myCar(){
			uni.navigateTo({
								      url: '../carinfo/mycar',
								  });
		},
		showModal(e) {
			this.modalName = e.currentTarget.dataset.target
		},
		hideModal(e) {
			this.modalName = null
		},
		submsg(){
			if(this.msg==""){
				uni.showToast({title:"请填建议"});
				return;
			} 
			if(this.phone==""){ 
			 uni.showToast({title:"请填写联系号码"});
			 return; 
			}
			//提交留言
			uni.request({
				header:{ 'Authorization' : 'Basic '+service.getUsers().Token},
				url: service.BaseUrl+'api/apiAdmin/AddProposal',
				method: 'POST',
				data: {
					Msg:_self.msg,
					Phone: _self.phone,
					Token:service.getUsers().Token
				},
				success: res => {
					if(res.data.Code==1){
						var dt=res.data.Data;
						this.modalName = null;
					    _self.msg="";	
					    _self.phone="";	
						uni.showToast({
							title:res.data.Msg
						}) 
					}
					else{
					
						uni.showToast({title:"操作失败"});
					}
				}
			});
		}
		,more(){
			uni.showModal({ //提醒用户更新
			    title: "关于我们",  
			    content: '我们是二手车车商联盟平台，是专为二手车商提供车辆信息化管理和共享服务，让同行帮你卖车，百倍扩大你的销量。开通请联系管理员，QQ微信：4935551998',  
			    
			})
		}
		,test(){
						uni.request({
								url: service.BaseUrl+'api/apicar/gets2?sf=sdfsxxxx',
							method: 'GET',
							data: {},
							headers: {Authorization:'Basic LR1oNhLm7h0dUhBalfz57/OlnXoBE4UV0opvF/LFE6C2e3tjdQwaMkKPxstW0OUSkfLf06MnnMs4oRGswtPH75EZ1tvJkH4WUACADY712uJ7JgWwaKMEtA=='
							              },
							success: res => {
								uni.showToast({
								    icon: 'none',
								    title: '成功',
								});
							},
							fail: () => {},
							complete: () => {}
						});

					}

	}
}
</script>

<style>
@import '../../common/common.css';
</style>
